﻿using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using Byond.Frontend;
using Utils;

namespace Byond.Standalone
{
	/// <summary>
	/// Interaction logic for MainWindow.xaml
	/// </summary>
	public partial class MainWindow : INotifyPropertyChanged
	{
		private readonly ByondControl _byondControl;

		private void Ctor()
		{
			//AvalonEditor.UseRichTextBox = true;

			MinimizeWindowStateCommand = new RelayCommand(() => WindowState = WindowState.Minimized);
			RestoreWindowStateCommand = new RelayCommand(() => WindowState = WindowState.Normal);
			MaximizeWindowStateCommand = new RelayCommand(() => WindowState = WindowState.Maximized);
			CloseWindowCommand = new RelayCommand(Close);
			StateChanged += (s, e) =>
				{
					OnPropertyChanged("CanRestoreWindowState");
					OnPropertyChanged("CanMaximizeWindowState");
				};

			DataContext = this;
			InitializeComponent();

			byondControlPlaceholder.Content = _byondControl;
		}

		public ICommand MinimizeWindowStateCommand { get; private set; }
		public ICommand RestoreWindowStateCommand { get; private set; }
		public ICommand MaximizeWindowStateCommand { get; private set; }
		public ICommand CloseWindowCommand { get; private set; }

		public bool CanRestoreWindowState { get { return WindowState == WindowState.Maximized; } }
		public bool CanMaximizeWindowState { get { return WindowState != WindowState.Maximized; } }

		protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
		{
			base.OnMouseLeftButtonDown(e);

			if (e.ClickCount != 1)
				return;
			DragMove();
			e.Handled = true;
		}

		public event PropertyChangedEventHandler PropertyChanged;
		private void OnPropertyChanged(string propertyName)
		{
			var handler = PropertyChanged;
			if (handler != null)
				handler(this, new PropertyChangedEventArgs(propertyName));
		}
	}
}
